<?php

class Rating extends CActiveRecord {

    const TYPE_USER = 1;
    const TYPE_COMMENT = 2;
    const TYPE_SERVICE = 3;
    const TYPE_SUGGEST = 4;

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return 'Rating';
    }

    public function rules() {
        return array(array('user_id, item_id, type', 'required'),);
    }

    public static function addNew($item_id, $type) {
        $rating = new Rating();
        $rating->user_id = Y::userId();
        $rating->item_id = $item_id;
        $rating->type = $type;
        $rating->save();
    }

}
